namespace MultiAgentsServer.Scripts.Database;

public class ManagerUsersDbRepository(DataBaseConnectService dbService)
{
    private readonly DataBaseConnectService _dbService = dbService;

    public ManagerUserDB? GetManagerUserById(int id)
    {
        var sql = "SELECT * FROM ManagerUsers WHERE Id = @Id";
        Dictionary<string, object> parameters = new() { { "@Id", id } };
        var result = _dbService.ExecuteQuery(sql, parameters);
        if (result.Count > 0)
        {
            return new ManagerUserDB(result[0]);
        }
        return null;
    }

    public ManagerUserDB? GetManagerUserByName(string name)
    {
        var sql = "SELECT * FROM ManagerUsers WHERE Name = @Name";
        Dictionary<string, object> parameters = new() { { "@Name", name } };
        var result = _dbService.ExecuteQuery(sql, parameters);
        if (result.Count > 0)
        {
            return new ManagerUserDB(result[0]);
        }
        return null;
    }

    public bool UpdateInvitationCode(int id, string InvitationCode)
    {
        var sql = "UPDATE ManagerUsers SET InvitationCode = @InvitationCode WHERE Id = @Id";
        Dictionary<string, object> parameters = new()
            {
                { "@Id", id },
                { "@InvitationCode", InvitationCode }
            };
        return _dbService.ExecuteNonQuery(sql, parameters) > 0;
    }
}
